import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    name: '登录',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: { keepAlive: true }
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
    meta: { keepAlive: true }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/',
    name: '我的信息',
    meta: { title: '我的信息', icon: 'el-icon-s-marketing', keepAlive: true },
    children: [
      {
        path: '/',
        name: '我的信息',
        component: () => import('@/views/dashboard/admin'),
        meta: { title: '我的信息', icon: 'el-icon-s-marketing', keepAlive: true }
      },
    {
      path: '/draggable',
      name: '首页装修',
      component: () => import('@/views/draggable/index'),
      meta: { title: '装修', icon: 'el-icon-s-marketing', keepAlive: true }
    },

    ]
  },
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/index',
    name: '数据大屏',
    children: [{
      path: 'index',
      name: '数据展示',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '数据展示', icon: 'el-icon-s-marketing', keepAlive: true }
    }]
  },
  {
    path: '/business',
    component: Layout,
    redirect: '/business/business',
    name: '商家管理',
    meta: { title: '商家管理', icon: 'el-icon-s-shop', },
    children: [
      {
        path: 'business',
        name: '我的店铺',
        component: () => import('@/views/business/business'),
        meta: { title: '我的店铺', icon: 'el-icon-shopping-bag-1', keepAlive: true }
      },
      // {
      //   path: 'msg',
      //   name: '消息通知',
      //   component: () => import('@/views/business/msg'),
      //   meta: { title: '消息通知', icon: 'el-icon-shopping-bag-1' }
      // },
      // {
      //   path: 'bidding',
      //   name: '竞价设置',
      //   component: () => import('@/views/business/bidding'),
      //   meta: { title: '竞价设置', icon: 'el-icon-shopping-bag-1' }
      // }

    ]
  },

  {
    path: '/commodity',
    component: Layout,
    redirect: '/commodity/primaryclassification',
    name: '商品管理',
    meta: { title: '商品管理', icon: 'el-icon-goods', keepAlive: true },
    children: [
      {
        path: 'primaryclassification',
        name: '商品分类',
        component: () => import('@/views/commodity/primaryclassification'),
        meta: { title: '商品分类', icon: 'el-icon-c-scale-to-original', keepAlive: true }
      },
      {
        path: 'specifications',
        name: '商品规格',
        component: () => import('@/views/commodity/specifications'),
        meta: { title: '商品规格', icon: 'el-icon-discount', keepAlive: true }
      },
      {
        path: 'goodslist',
        name: '商品列表',
        component: () => import('@/views/commodity/goodslist'),
        meta: { title: '商品列表', icon: 'el-icon-shopping-bag-1', keepAlive: true }
      },
      {
        path: 'freight',
        name: '运费模版',
        component: () => import('@/views/commodity/freight'),
        meta: { title: '运费模版', icon: 'el-icon-shopping-bag-1', keepAlive: true }
      },
      {
        path: 'freightList',
        name: '模版设置',
        component: () => import('@/views/commodity/freightList'),
        meta: { title: '模版设置  ', icon: 'el-icon-shopping-bag-1', keepAlive: true }
      },
      {
        path: 'addgoods',
        name: '添加商品',
        hidden: true,
        component: () => import('@/views/commodity/addgoods'),
        meta: { title: '添加商品', icon: 'el-icon-shopping-bag-1'}
      },

    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/order',
    name: '订单管理',
    meta: { title: '订单管理', icon: 'el-icon-s-order', keepAlive: true },
    children: [
      {
        path: 'order',
        name: '订单列表',
        component: () => import('@/views/order/order'),
        meta: { title: '订单列表', icon: 'el-icon-s-order', keepAlive: true }
      },
      {
        path: 'refundsList',
        name: '售后订单',
        component: () => import('@/views/order/refundsList'),
        meta: { title: '售后订单', icon: 'el-icon-s-order', keepAlive: true }
      },
      {
        path: 'orderDetails',
        name: '订单详情',
        hidden: true,
        component: () => import('@/views/order/orderDetails'),
        meta: { title: '订单详情', icon: 'el-icon-shopping-bag-1',}
      }
    ]
  },
  {
    path: '/finance',
    component: Layout,
    redirect: '/finance/wallet',
    name: '财务管理',
    meta: { title: '财务管理', icon: 'el-icon-s-finance', keepAlive: true },
    children: [
      {
        path: 'wallet',
        name: '钱包记录',
        component: () => import('@/views/finance/wallet'),
        meta: { title: '钱包记录', icon: 'el-icon-s-finance', keepAlive: true }
      },
      // {
      //   path: 'setwallet',
      //   name: '钱包配置',
      //   component: () => import('@/views/finance/setwallet'),
      //   meta: { title: '钱包配置', icon: 'el-icon-set-up' }
      // }

    ]
  },
  {
    path: '/setup',
    component: Layout,
    redirect: '/setup/api',
    name: '系统设置',
    meta: { title: '系统设置', icon: 'el-icon-s-tools', keepAlive: true },
    children: [
      {
        path: 'api',
        name: 'api管理',
        component: () => import('@/views/setup/api'),
        meta: { title: 'api管理', icon: 'el-icon-link', keepAlive: true }
      },
      {
        path: 'administrators',
        name: '管理员',
        component: () => import('@/views/setup/administrators'),
        meta: { title: '管理员', icon: 'el-icon-user-solid', keepAlive: true }
      },
      // {
      //   path: 'menu',
      //   name: '菜单管理',
      //   component: () => import('@/views/setup/menu'),
      //   meta: { title: '菜单管理', icon: 'el-icon-menu' }
      // },
      {
        path: 'modifyPassword',
        name: '修改密码',
        component: () => import('@/views/setup/modifyPassword'),
        meta: { title: '修改密码', icon: 'el-icon-unlock', keepAlive: true }
      },
      {
        path: 'refundsAddress',
        name: '退货地址',
        component: () => import('@/views/setup/refundsAddress'),
        meta: { title: '退货地址', icon: 'el-icon-unlock', keepAlive: true }
      }

    ]
  },


  // {//外链
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
